package dao

import (
	"github.com/jinzhu/gorm"
	"vtrip/internal/model"
)

func (d *Dao) GetUserWithWChatId(nickName, wChatId, avatarUrl string) (model.User, error) {
	// 根据微信 id 查询匹配的记录
	user := model.User{
		NickName:  nickName,
		WChatId:   wChatId,
		AvatarUrl: avatarUrl,
	}
	result, err := user.Get(d.engine)

	// 如果未找到符合条件的记录
	if err == gorm.ErrRecordNotFound {
		// 新增一条记录
		err = user.Create(d.engine)
	}
	return result, err
}
